import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

data  = pd.read_csv('boston_house.csv')
# print(data.info())
y = data['MEDV']
X = data.drop('MEDV',axis=1)
y = np.array(y)
X = np.array(X)

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.15)

lr = LinearRegression()
lr.fit(X_train,y_train)

y_true = lr.predict(X_test)

print(mean_squared_error(lr.predict(X_test),y_test))





from 线性回归模型的类封装 import LinearRegression
from sklearn.preprocessing import StandardScaler

y = data['MEDV']
X = data.drop('MEDV',axis=1)
y = np.array(y)
X = np.array(X)

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.15)
ss = StandardScaler()
ss.fit(X_train)

X_train = ss.transform(X_train)
X_test = ss.transform(X_test)

lr = LinearRegression()
lr.fit(X_train,y_train)

print(mean_squared_error(lr.predict(X_test),y_test))